package com.itheima.app.manager;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.mongo.Video;
import com.itheima.service.mongo.VideoService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class VideoMQManager {
    //针对动态的操作
    public static final Integer VIDEO_PUBLISH = 1;// 发视频
    public static final Integer VIDEO_LIKE = 2;// 点赞
    public static final Integer VIDEO_DISLIKE = 3;// 取消点赞
    public static final Integer VIDEO_COMMENT = 4;// 评论视频

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Reference
    private VideoService videoService;

    public void sendMsg(String videoId,Integer type) {
        //获取当前登录用户
        Long userId = UserHolder.getId();
        //查询视频信息
        Video video = videoService.findById(videoId);
        //构建mq消息对象
        Map map = new HashMap();
        map.put("userId", userId);
        map.put("type", type);
        map.put("vid", video.getVid());
        rocketMQTemplate.convertAndSend("tanhua-video-161",map);
    }

}
